import { Bind, Body, Controller, Delete, Get, HttpCode, Param, Post, Put, Query, Redirect } from "@nestjs/common";
import { UserCreateDto } from "src/core/dto/user-create.dto";
import { UserDto } from "src/core/dto/user.dto";

@Controller("user")
export class UserController {//定义一个类
    @Get('profile')//获取资源
    @HttpCode(500)//虽然是500但是也请求成功了，默认情况下不定义状态码就是200
    getUser(): string {
        return "This is the user's profile page";//返回单个用户资源
    }
    @Get('settings/notifications')//获取资源
    getUser1(): string {
        return "This is the user's notification settings page";//返回单个用户资源
    }
    // @Get(':id/:userName')
    // getUsers(@Param('id') id:string,@Param('userName') userName:string): string {
    //     return `列表用户:当前用户id为：${id},用户名为：${userName}`
    // }
    @Get('tongpeifu/*a/:user')
    @Redirect('https://www.baidu.com', 301)
    getUsers2(@Param('user') user: string): string {
        // return '列表用户jiejiejie ,通配符的*必须以user开头'
        return `欢迎访问【${user}】的个人信息`
    }
    // @Get(':id')
    // @Bind(Param())
    // findOne(params) {
    //     console.log(params.id)
    //     return `当前用户的id为${params.id}`
    // }
    @Get('two/:id/:username')
    getUser2(@Param('id') id: string, @Param('username') username: string) {
        return `当前用户id为${id},用户名为:${username}`
    }
    @Put("update")//更新资源
    updateUser(): string {
        return '更新资源'
    }
    @Post('qianshen')
    createUser1(): string {
        return "创建用户"
    }
    @Delete()
    DeleteUser(): string {
        return "删除用户"
    }
    //访问/
    //使用put装饰器,用postman测试输出更新资源,访问user/update

    @Get()
    get(): string {
        return '列表用户'
    }
    @Post('create')
    createUser(
        @Query('username') username: string,
        @Query('age') age: string,
        @Query('gender') gender: string,
    ) {
        return {
            username,
            age,
            gender
        }
    }
    @Post('query')
    createUser2(
        @Query('username') username: string,
        @Query('age') age: string,
        @Query('gender') gender: string,
        @Query('play') play: string,
    ) {
        return {
            username,
            age,
            gender,
            play
        }
    }
    @Post()
    createUser3(@Body() UserCreateDto: UserCreateDto) {
        return UserCreateDto;
    }
    @Get()//获取资源
    async searchUsers(): Promise<UserDto[]> {
        return [];
    }
    @Get(':id')
    getUser4(@Param('id') id: string): Promise<UserDto> {
        //根据id拿到用户返回的信息
        return Promise.resolve({
            id,
            username: '张三',
            age: 33,
            gender: '男',
            createTime: '2021-08-09 00:00:00',
            updateTime: '2021-08-09 00:00:00'
        });
    }
    //创建用户
    @Post()
    createUser6() {

    }
    //更新资源
    @Put(':id')
    updateUsers(@Param('id') id: string): Promise<UserDto> {
        return Promise.resolve({
            id,
            username: '张三',
            age: 33,
            gender: '男',
            createTime: '2021-08-09 00:00:00',
            updateTime: '2021-08-09 00:00:00'
        });
    }

    @Delete(':id')
    deleteUsers(@Param('id') id: string):string {
        return `删除用户${id}`;
    }

}

